package org.atf.model.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.atf.model.entity.EncryptDecryptHelper;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

public class EntityManagerUtil {
//	 private static final String ATF_CONFIG_EM = "ATFJPA";
//	 private static EntityManagerFactory factory = null;
//	
//	 public static EntityManager getEntityManager() {
//			return getEntityManager(ATF_CONFIG_EM);
//	 }
//	 public static EntityManager getEntityManager(String entityManagerName) {
//		if (factory == null) {
//			initFactory(entityManagerName);
//		}	
//		return factory.createEntityManager();			
//	 }	
//	 public static void initFactory(String entityManagerName) {		
//			if (factory == null) {		
//				factory = Persistence.createEntityManagerFactory(entityManagerName);
//			}
//		}
	private static final EntityManagerFactory emFactory;
	public static String encryptionPassword="hibernateStringEncryptor123454*";
	static {
		 //  EncryptDecryptHelper.init(encryptionPassword);
		   emFactory = Persistence.createEntityManagerFactory("ATFJPA");
	}
	public static EntityManager getEntityManager(){
		return emFactory.createEntityManager();
	}
	
	
//	private static EntityManagerFactory factory = Persistence.createEntityManagerFactory("ATFJPA");
//    
//    private static ThreadLocal<EntityManager> entityManagerLocal = new ThreadLocal<EntityManager>();
//    
//    public static EntityManager getEntityManager()
//    {
//            EntityManager em = entityManagerLocal.get();
//            System.out.println("EM:*****"+em);
//            if (em == null)
//            {
//            	   EncryptDecryptHelper.init(encryptionPassword);
//                    em = factory.createEntityManager();
//                    entityManagerLocal.set(em);
//                    
//                //    StandardPBEStringEncryptor strongEncryptor = new StandardPBEStringEncryptor();
//                  //  strongEncryptor.setPassword(encryptionPassword);
//                    //HibernatePBEEncryptorRegistry registry =
//                    //	      HibernatePBEEncryptorRegistry.getInstance();
//                    //registry.registerPBEStringEncryptor("hibernateStringEncryptor", strongEncryptor);
//            }
//            return em;
//    }
}
